<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AddressController extends Controller
{
    //订单列表
    public function insert(Request $request)
    {   
       // dd($request->all());
    	// $data = $request->except('_token');
        $data = $request->only('dizhi_name','phone','sheng','shi','xian','content','statuss');
    	$data['statuss'] = 1;
    	$data['user_name'] = session('name');

    	// dd($data);
    	$id = DB::table('address')->insertGetId($data);
        // dd($id);
    	if($id){
    		return back();
    	}else{
    		die('添加失败');
    	}
    }
     public function update(Request $request){
        // echo "string";die;
        $did = $request->only('did');
        $uname = session('name');
        $res = DB::table('address')->where('id',$did)->where('statuss','2')->first();
        if($res){
            echo 3;
        }else{
            $ress = DB::table('address')->where('user_name',$uname)->update(['statuss'=>'1']);
            // dd($res);
            $order = DB::table('address')->where('id',$did)->update(['statuss'=>'2']);
            // dd($order);
            if($order){
                echo 1;
            }else{
                echo 2;
            }
            
        }
    }
    public function delete(Request $request){
        $uname = session('name');
        $did = $request->input('did');
        // dd($did);
        $res = DB::table('address')->where('id',$did)->delete();
        if($res){
            echo 1;
        }else{
            echo 0;
        }


    }
}
